package com.osc.exam.controller;

import com.osc.exam.constant.GlobalConstant;
import com.osc.exam.entity.AdminResponse;
import com.osc.exam.entity.domain.User;
import com.osc.exam.entity.vo.UserVO;
import com.osc.exam.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;



/**
 * 用户相关功能的接口
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api("用户操作相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登陆功能
     * @param userVO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation(value = "用户登陆操作--左坤", notes = "用户登陆操作")
    public ResponseEntity login(@RequestBody UserVO userVO){
        userService.selectByUserName(userVO.getUsername(), userVO.getPassword());
        return ResponseEntity.status(HttpStatus.OK)
                .body(AdminResponse.result(GlobalConstant.SUCCESS,"登陆成功!"));
    }

    /**
     * 注册功能
     * @param user
     * @return
     */
    @PostMapping("/register")
    @ApiOperation(value = "注册用户功能--赵琳", notes = "注册用户功能")
    public ResponseEntity register(@RequestBody User user){
        userService.register(user);
        return ResponseEntity.status(HttpStatus.OK)
                .body(AdminResponse.result(GlobalConstant.SUCCESS,"注册成功!"));
    }



}
